package com.qingfeng.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * @ProjectName TestController
 * @author qingfeng
 * @version 1.0.0
 * @Description TODO
 * @createTime 2021/4/3 0003 20:29
 */
@Slf4j
@RestController
public class HelloController {

    /**
     * @title index
     * @description 首页
     * @author Administrator
     * @updateTime 2021/4/19 0019 13:00
     */
    @GetMapping("index")
    public String hello(String name){
        log.info("青锋欢迎您！！！");
        System.out.println("青锋hello模块");
        return "青锋欢迎您！！！";
    }

    /**
     * @title userAdd
     * @description 权限测试
     * @author Administrator
     * @updateTime 2021/4/19 0019 13:00
     */
    @GetMapping("userAdd")
    @PreAuthorize("hasAnyAuthority('user:add')")
    public String userAdd(){
        return "拥有'user:add'权限";
    }

    /**
     * @title user
     * @description 获取当前登录用户
     * @author Administrator
     * @updateTime 2021/4/19 0019 13:00
     */
    @GetMapping("user")
    public Principal user(Principal principal) {
        return principal;
    }

}